<?php
class Latest extends CWidget
{
	public $bloglist = array();
	public $htmlOptions = array();
	
	public $data;
	public $limit = 5;
	public $slice = 50;
	
	public $timeFormat = 'Y-m-d h:i';
	
	public $view = 'news';
	
	public function getProducts()
	{
		$products = Category::model()->findAll();
		$i = 0;
		foreach ($products as $data){
			$this->products[$i] = $data->attributes;
			$i++;
		}
		$this->products = Category::model()->getChildrenArray($this->products,7);
		
	}
	
	public function getNews()
	{
		$news = Article::model()->findAll(array(
			'order'=>'arc_id DESC',
			'limit'=>$this->limit
				
		));
		$this->data = $news;
	}
	
	public function getFaqs()
	{
		$faq = Faq::model()->findAll(array(
			'order'=>'faq_id DESC',
			'limit'=>$this->limit
		));
		
		$this->data = $faq;
	}
	
	public function run()
	{
	
		if($this->view == 'news')
			$this->getNews();
		elseif ($this->view == 'faq')
			$this->getFaqs();
		elseif ($this->view == 'product')
			$this->getProducts();
		
		$this->render($this->view,array(
			'list'=>$this->data
		));
	}
}
?>